package com.emergency.embackend.controller;

import com.emergency.embackend.common.PageParams;
import com.emergency.embackend.common.R;
import com.emergency.embackend.param.AddQuizSuitParam;
import com.emergency.embackend.param.QuizSuitParam;
import com.emergency.embackend.service.QuizSuitService;
import com.emergency.embackend.utils.UserHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;


/**
 * @author chddd
 * @description
 * @create 2024/3/11 16:52:55
 */
@RestController
@Slf4j
@RequestMapping("quiz/suit")
public class QuizSuitController {
    @Autowired
    private QuizSuitService quizSuitService;

    @PostMapping("/page")
    public R page(@RequestBody QuizSuitParam quizSuitParam) {
        if (ObjectUtils.isEmpty(quizSuitParam)) {
            return R.error("参数异常");
        }
        return R.ok().put("data", quizSuitService.page(quizSuitParam));
    }

    @GetMapping("/delete")
    public R delete(@RequestParam("quizSuitId") Long quizSuitId){
        if(quizSuitId == null ){
            return R.error("参数异常");
        }
        quizSuitService.delete(quizSuitId);
        return R.ok();
    }
    @PostMapping("/add")
    public R add(@RequestBody AddQuizSuitParam addQuizSuitParam){
        if(ObjectUtils.isEmpty(addQuizSuitParam)){
            return R.error("参数异常");
        }
        return R.ok().put("data",quizSuitService.add(addQuizSuitParam));
    }
    @PostMapping("update")
    public R update(@RequestBody AddQuizSuitParam addQuizSuitParam){
        if(ObjectUtils.isEmpty(addQuizSuitParam)){
            return R.error("参数异常");
        }
        quizSuitService.update(addQuizSuitParam);
        return R.ok();
    }
    @PostMapping("getUserSuitRecord")
    public R getUserSuitRecord(@RequestBody QuizSuitParam quizSuitParam){
        if(ObjectUtils.isEmpty(quizSuitParam)){
            return R.error("参数异常");
        }
        Long userId = UserHolder.getUser().getId();
       return R.ok().put("data",quizSuitService.getUserSuitRecord(quizSuitParam,userId));
    }
    @PostMapping("getRecentlySuit")
    public R getRecentlySuit(@RequestBody PageParams pageParams){
       return R.ok().put("data", quizSuitService.getRecentlySuit(pageParams));
    }
    @PostMapping("getRecommendSuit")
    public R getRecommendSuit(@RequestBody QuizSuitParam quizSuitParam){
        return R.ok().put("data",quizSuitService.getRecommendSuit(quizSuitParam));
    }

}
